// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.ui.prefs.connectivity.models;

import org.dengues.commons.connectivity.EDatabaseType;
import org.eclipse.swt.graphics.Image;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 1 2006-09-29 17:06:40Z qiang.zhang $
 * 
 */
public abstract class ConnectivityCategory implements Comparable, Cloneable {

    private String[] driverClasses;

    private ConnectivityCategory parent;

    private String id;

    private Image image;

    private EDatabaseType type;

    /**
     * Qiang.Zhang.Adolf@gmail.com DBCategory constructor comment.
     */
    public ConnectivityCategory() {
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com DBCategory constructor comment.
     */
    public ConnectivityCategory(EDatabaseType type) {
        this.type = type;
        if (type != null) {
            setId(type.getDisplayName());
            setImage(type.getImage());
            initDriverClasses();
        }
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "initDriverClasses".
     */
    protected void initDriverClasses() {
        String driver = getType().getDriver();
        if (driver != null) {
            driverClasses = new String[] { driver };
        }
    }

    /**
     * Getter for id.
     * 
     * @return the id
     */
    public String getId() {
        return this.id;
    }

    /**
     * Sets the id.
     * 
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object o) {
        if (o instanceof ConnectivityCategory) {
            ConnectivityCategory category = (ConnectivityCategory) o;
            return category.getId().compareTo(getId());
        }
        return 0;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!this.getClass().equals(obj.getClass())) {
            return false;
        }
        if (!(obj instanceof ConnectivityCategory)) {
            return false;
        }
        ConnectivityCategory category = (ConnectivityCategory) obj;
        return category.getId().equals(getId());
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return getId();
    }

    /**
     * Getter for parent.
     * 
     * @return the parent
     */
    public ConnectivityCategory getParent() {
        return this.parent;
    }

    /**
     * Sets the parent.
     * 
     * @param parent the parent to set
     */
    public void setParent(ConnectivityCategory parent) {
        this.parent = parent;
    }

    /**
     * Getter for image.
     * 
     * @return the image
     */
    public Image getImage() {
        return this.image;
    }

    /**
     * Sets the image.
     * 
     * @param image the image to set
     */
    public void setImage(Image image) {
        this.image = image;
    }

    public EDatabaseType getType() {
        return this.type;
    }

    public String[] getDriverClasses() {
        return this.driverClasses;
    }

    public void setDriverClasses(String[] driverClasses) {
        this.driverClasses = driverClasses;
    }

    public void setType(EDatabaseType type) {
        this.type = type;
    }

}
